package com.whu.dao;

import com.whu.domain.Commodity;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CommodityDao {

    /**
     *商品增加
     */
    @Insert("insert into commodity(id,name,description,money) values(#{id},#{name},#{description},#{money})")
    int add(Commodity commodity);

    /**
     * 商品删除
     */
    @Delete("delete from commodity where id = #{id}")
    int delete(Integer id);

    /**
     * 修改商品信息
     */
    @Update("update commodity set name = #{name},description = #{description},money = #{money} where id = #{id}")
    int update(Commodity commodity);

    /**
     * 根据id查询商品
     */
    @Select("select * from commodity where id = #{id}")
    List<Commodity> getById(Integer id);

    /**
     * 根据name查询商品
     */
    @Select("select * from commodity where name = #{name}")
    List<Commodity> getByName(String name);

    /**
     *查询全部商品
     */
    @Select("select * from commodity")
    List<Commodity> getAll();
}
